package com.woniu.mall.controller;

import com.woniu.common.annotation.LoginUser;
import com.woniu.common.entity.Result;
import com.woniu.mall.DTO.MallStoreDTO;
import com.woniu.mall.VO.StoreDetailVO;
import com.woniu.mall.VO.StoreListVO;
import com.woniu.mall.service.IMallStoreService;
import com.woniu.user.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 坤
 * @since 2023-05-22
 */
@RestController
@RequestMapping("/mallStore")
@Api(tags = "商家管理")
@Slf4j
public class MallStoreController {
    @Autowired
    private IMallStoreService storeService;

    @ApiOperation("搜索商家")
    @PostMapping("/listSearch/{title}")

    public Result listSearch(@PathVariable String title) {
        List<StoreListVO> storeListVOList = storeService.listSearch(title);
        return Result.ok(storeListVOList);
    }

    @ApiOperation("商家详情")
    @PostMapping("/detail/{sid}")
    public Result showDetail(@PathVariable Integer sid) {
        StoreDetailVO storeDetailVO = storeService.showDetail(sid);
        return Result.ok(storeDetailVO);
    }

    @ApiOperation("新增商家")
    @PostMapping("/saveStore")
    public Result saveStore(@RequestBody MallStoreDTO mallStoreDTO, @LoginUser UserLoginVO userLoginVO) {

        Boolean flag = storeService.saveStore(mallStoreDTO, userLoginVO);
        return Result.ok(flag);
    }

    @ApiOperation("修改商家")
    @PostMapping("/updateStore")
    public Result updateStore(@RequestBody MallStoreDTO mallStoreDTO, @LoginUser UserLoginVO userLoginVO) {
        Boolean flag = storeService.updateStore(mallStoreDTO, userLoginVO);
        return Result.ok(flag);
    }

    @ApiOperation("删除商家")
    @GetMapping("/deleteStore")
    public Result deleteStore(@LoginUser UserLoginVO userLoginVO){
        Boolean flag = storeService.deleteStore(userLoginVO);
        return Result.ok(flag);
    }
}
